﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module.Common.Models;
using Module.Core.BusinessLogic;
using Module.Core.Common;
using Module.Core.EntitiesInfo;
using Module.Core.LoginSystem.Commons.Framwork;
using Module.Core.LoginSystem.Commons.Utilities;
namespace Web.Cms.ConfigKeyword
{
    public partial class ConfigManager : AdminUserControl
    {
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            try
            {
                CHRTList<ConfigKeywordInfo> configKeywordInfo = ConfigKeywordBL.SelectAll();
                if (configKeywordInfo != null && configKeywordInfo.Count > 0)
                {
                    grvConfig.DataSource = configKeywordInfo;
                    grvConfig.RowDataBound += new GridViewRowEventHandler(grvConfig_RowDataBound);
                    grvConfig.DataBind();
                }
            }
            catch (Exception ex)
            {
                ltrJump.Text = ex.Message;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        void grvConfig_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = Convert.ToString(e.Row.DataItemIndex + 1);
            }
        }
        protected void grvConfig_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int _ConfigId = ConvertUtility.ToInt32(e.CommandArgument);
                switch (e.CommandName)
                {
                    case "deleteConfig":
                        try
                        {
                            ConfigKeywordBL.Delete(_ConfigId);                           
                            Response.Redirect("/cms/Default.aspx?ctrlkey=configManager");
                        }
                        catch (Exception ex)
                        {
                            ltrJump.Text = ex.Message;
                        }
                        break;
                }              
            }
            catch (Exception ex)
            {
                ltrJump.Text = ex.Message;
            }
        }
    }
}